package com.hdaccp.news1.service.imple;

import com.hdaccp.news1.entity.News;
import com.hdaccp.news1.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private EntityManager entityManager ;
    @Override
    public List<News> queryTop(int top) {
        Query query = entityManager.createQuery("select n from News n") ;
        if(top>0){
            query.setFirstResult(0) ;
            query.setMaxResults(5) ;
        }
        return query.getResultList();
    }
}
